package com.run2code.idea.plugin.codegenerate.biz.db.bizdata;

import com.run2code.idea.plugin.codegenerate.biz.db.metadata.Field;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
 * 业务模型-mapper
 * 关注公众号【奔跑的码畜】，一起进步不迷路
 *
 * @author 第七人格
 * @date 2023/10/30
 */
public class Mapper extends Base {

    private Entity entity;

    public Mapper(String comment, String name, Entity entity) {
        super(comment, name);
        this.entity = entity;
    }

    public Entity getModel() {
        return entity;
    }

    @Override
    public Set<String> getImports() {
        Set<String> imports = new HashSet<>();
        imports.add(entity.getPackage() + "." + entity.getSimpleName());
        List<Field> fields = entity.getFields();
        for (Field field : fields) {
            if (field.isId() && field.isImport()) {
                imports.add(field.getTypeName());
                break;
            }
        }
        return imports;
    }

}
